<html>
<head>
    <title>这是我的昵称</title>
</head>
<script src="/jquery/jquery.js"></script>
<script src="/layui/layui.js"></script>
<body style="background:#F4F4F4";>
<center>
    <div style="background:#FFFFFF;margin-top:250px;">
        <h1>请在下方修改你的昵称噢</h1>
        <form action="" method="post" id="form">
            @csrf
            <span style="font-size:23px;"> 昵称：</span><input type="text" name="name" id="add" value="{{$row->name}}" style="width:300px;height:50px;"/><br/><br/>
            <input type="submit" value="提交" id="submit" style="width:200px;height:30px;margin-left:65px">
        </form>
    </div>
</center>
</body>
<script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
<script>
    $(function(){
        $('#submit').click(function () {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
            });
            var form = $('#form').serialize();
            var add =  $('#add').val();
            layui.use('layer', function() {
                var layer = layui.layer;
                if (!add) {
                    layer.msg('昵称不能为空');
                    location.href = '/add_name';
                    return false;
                    exit;
                }
                if (add.length<5) {
                    layer.msg('昵称长度不能小于5位');
                    location.href = '/add_name';
                    return false;
                    exit;
                }else if (add.length>10) {
                    layer.msg('昵称长度不能大于10位');
                    location.href = '/add_name';
                    return false;
                    exit;
                }else
                {
                  $.get({
                        url:"name_update",
                        data: form,
                        success:function (data) {
                            layui.use('layer', function(){
                                var layer = layui.layer;
                                if(data.code=='1') {
                                    layer.open({
                                        title: '昵称'
                                        , skin: 'msg'
                                        , content: data.name
                                        , yes: function () {
                                            location.href = data.url;
                                        }
                                    });
                                }else if(data.code=='-1'){
                                    layer.open({
                                        title: '昵称'
                                        , skin: 'msg'
                                        , content: data.name
                                        , yes: function () {
                                            location.href = '/add_name';
                                        }
                                    });
                                }
                            });
                        }
                    });
                }
            });
            return false;
        });
    });
</script>
</html>
